<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_search
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.model');

/**
 * Search Component Search Model
 *
 * @package		Joomla.Site
 * @subpackage	com_search
 * @since 1.5
 */
class NewsModelNews extends JModel
{
	function latestNews( $catid ){
		$db = $this->getDbo();
		$query = "SELECT * FROM `#__content` WHERE `state` = 1 AND catid = ".$catid." ORDER BY DATE(`created`) DESC  LIMIT 0, 1";
		$db->setQuery($query);
		return $db->loadObject();
	}
	function listNews( $limitstart, $limit, $catid){
		$db = $this->getDbo();
		$query = "SELECT * FROM `#__content` WHERE `state` = 1 AND catid = ".$catid." ORDER BY DATE(`created`)";
		$db->setQuery($query,$limitstart,$limit);
		return $db->loadObjectList();
	}
	function listNewsTotal( $id, $catid ){
		$db = $this->getDbo();
		$query = "SELECT COUNT(*) FROM `#__content` WHERE `state` = 1 AND catid = ".$catid." AND id not in ($id)";
		//echo $query;
		$db->setQuery($query);
		return $db->loadResult();
	}
	function latestNewsById($catid, $id){
		$db = $this->getDbo();
		$query = "SELECT * FROM `#__content` WHERE `state` = 1 AND catid = ".$catid." AND id = ".$id;
		$db->setQuery($query,$limitstart,$limit);
		return $db->loadObject();
	}
	function latestNewsSlide( $catid ){
		$db = $this->getDbo();
		$query = "SELECT * FROM `#__content` WHERE `state` = 1 AND catid = ".$catid." ORDER BY DATE(`created`) DESC  LIMIT 0, 5";
		$db->setQuery($query);
		return $db->loadObjectList();
	}
}
